<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html> 
  <head> 
    <title>AJAX Foundations: JavaScript and XML</title> 
    <script type="text/javascript" src="books.js"></script> 
    <script type="text/javascript" src="loadxmldoc.js"></script>
  </head> 
  <body onload="process()"> 
    Server, tell me your favorite books! <br />
<script type="text/javascript">
function get_firstChild(n)
{
y=n.firstChild;
while (y.nodeType!=1)
  {
  y=y.nextSibling;
  }
return y;
}


xmlDoc=loadXMLDoc("books.xml");

h=xmlDoc.documentElement.childNodes;
x=get_firstChild(xmlDoc.getElementsByTagName("books")[0]);


for (i=0;i<x.length;i++)
{ 
if (x[i].nodeType==1)
  {//Process only element nodes (type 1) 
  document.write(x[i].nodeName);//lay duoc node dau tien cap 1 la book, nau lay 
  //them gia tri no thi x[i].childNodes[0].nodeValue
  document.write("<br />");
  
  y=x[i].childNodes;// y la node cap 2, con cua x.
  for (j=0;j<y.length;j++)
	{ 
	if (y[j].nodeType==1)
	  {//Process only element nodes (type 1) 
	  document.write(y[j].nodeName);
	  //lay duoc node dau tien cap 1 la book, nau lay 
  //them gia tri no thi y[j].childNodes[0].nodeValue
	  document.write("<br />");
	
	  
	  } 
	}

  
  } 
}

</script>
    <br/>
    Doan thu 2 chay len 
    <div id="myDivElement" /> 
    
  </body> 
</html> 